package com.ll.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class OrderConfirmVo {

    //地址
    @Setter
    @Getter
    List<MemberAddressVo> address = new ArrayList<>();

    //购物清单
    @Setter
    @Getter
    List<CartItemVo> items = new ArrayList<>();

    //发票。。优惠


    @Setter
    @Getter

    String orderToken;//防止接口重复提交

    @Setter
    @Getter
    Integer integration;//会员积分


    BigDecimal total;//总金额

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if (items.size() > 0) {
            for (CartItemVo item : items) {
                BigDecimal price = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));

                total = total.add(price);
            }
        }
        return total;
    }


    private Integer count;

    @Getter
    @Setter
    private Map<Long, Boolean> hasStock;//是否有货

    public Integer getCount() {
        Integer i = 0;
        if (items.size() > 0) {
            for (CartItemVo item : items) {
                i = i + item.getCount();
            }
        }
        return i;
    }

    BigDecimal payPrice;//支付金额

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
